var $PN="/TopNewsManagerV2";
var $LINKDATA="http://tnewsimg.rolo.vn:8080";
//var $LINKDATA="http://localhost/newsimg";
XHR = function(method,receiver){
	this.method = method||"Post";
	this.running = false;
	this.xhr = this._getXHR();
	this.receiver = receiver;
};
XHR.Delegate=function(){
   var Q= XHR.ToArray(arguments, 2);
   var I=arguments[0], bo=arguments[1];
   return function(){
      var aC= XHR.ToArray(arguments);
      return bo.apply(I, Q.concat(aC));
   };
};
XHR.ToArray=function(j, start, aD){
   var aY=[];
   start=start||0;
   aD=aD||j.length;
   if(start<=aD)for(var i=start; i<aD; ++i)aY.push(j[i]); return aY;
};
XHR.prototype={
	send : function (url,data){
		this.data=data;
		if (this.running) return this;
		this.running = true;
		if(data!=null&&this.method.toLowerCase()=="get"){
			url += ((url.indexOf("?")!=-1) ? "&" : "?") + this._toQueryString(data);
			data = null;
		}
		
		this.xhr.open(this.method.toUpperCase(), url, true);
		this.xhr.onreadystatechange = XHR.Delegate(this,this._onStateChange);
		this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
		this.xhr.send(this._toQueryString(data));
	},
	_getXHR : function(){
		return (window.XMLHttpRequest)?new XMLHttpRequest():(window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):false);
	},
	_toQueryString : function(source){
		if (typeof source == "string") return source;
		var queryString = [];
		for (var property in source) queryString.push(encodeURIComponent(property) + "=" + encodeURIComponent(source[property]));
	    return queryString.join("&");
	},
	_onStateChange : function(){
		if (this.xhr.readyState != 4 || !this.running) return;
		this.running = false;
		if(this.receiver)this.receiver.call(null,{p:this.data, text:this.xhr.responseText,xml:this.xhr.responseXML});
		this.xhr.onreadystatechange = function(){};
	}
};
var XML=function(r){
	this.xml;
	this.root;
	this.value=true;
	this.msg;
	this.init(r);
};
XML.prototype.init=function(r){
	this.xml=r.xml;
	this.root=this.getRoot();
	this.value=(this.root.getAttribute("value")=="true")?true:false;
	this.msg=this.root.getAttribute("msg");
};
XML.prototype.getRoot=function(){
	return this.xml.getElementsByTagName("root")[0];
};
XML.prototype.get=function(name){
	return this.xml.getElementsByTagName(name);
};
